<?php
/**
 * 短信发送操作类
 * User: dxk
 * Date: 2020/07/17
 */
namespace App\Library\Service;

use App\Library\Service\SMS\Mandao;
use App\Library\Service\SMS\Mengwang;
use App\Library\Service\SMS\SMSContract;
use App\Library\Service\SMS\Yunpian;

class SMS
{
    const CHANNEL_YUNIAN = 1;
    const CHANNEL_MANDAO = 2;
    const CHANNEL_MENGWANG = 3;
    public static $channels = [
        self::CHANNEL_MANDAO => [
            'channel_type' => self::CHANNEL_MANDAO,
            'channel_name' => '漫道'
        ],
    ];
    protected static $instance;

    /**
     * @param $send_channel_id
     * @return SMSContract
     * @throws \Exception
     */
    public static function channel($send_channel_id)
    {
        $send_channel_id = (int)$send_channel_id;
        switch ($send_channel_id) {
            case self::CHANNEL_YUNIAN:
                $instance = new Yunpian();
                break;
            case self::CHANNEL_MANDAO:
                $instance = new Mandao();
                break;
            case self::CHANNEL_MENGWANG:
                $instance = new Mengwang();
                break;
            default:
                throw new \Exception('不存在的短信服务通道');
        }
        static::$instance = $instance;
        return $instance;
    }

    public function __call($method, $parameters)
    {
        return call_user_func_array([static::$instance, $method], $parameters);
    }
}
